﻿
(function () {
    appModule.controller('common.views.workFlow_Processs.createOrEditModal', [
         '$scope', '$uibModalInstance', 'abp.services.app.workFlow_Process', 'workFlow_ProcessId', 'workFlow_Process', 'abp.services.app.workFlow', 'abp.services.app.workFlow_TableName',
        function ($scope, $uibModalInstance, workFlow_ProcessService, workFlow_ProcessId, workFlow_Process, workFlowService, workFlow_TableNameService) {
            var vm = this;
            vm.saving = false;
            //首先将workFlow_Process数据设置为null
            vm.workFlow_Process = null;



            //触发保存方法
            vm.save = function () {
                vm.saving = true;
                workFlow_ProcessService.createOrUpdateWorkFlow_ProcessAsync({ workFlow_ProcessEditDto: vm.workFlow_Process }).then(function () {
                    abp.notify.info(app.localize('SavedSuccessfully'));
                    $uibModalInstance.close();
                }).finally(function () {
                    vm.saving = false;
                });


            };
            //取消关闭页面
            vm.cancel = function () {
                $uibModalInstance.dismiss();
            };

            //初始化页面
            function init() {

                //绑定流程名称
                workFlowService.getAllWorkFlowListAsync().then(function (result) {
                    vm.workFlowList = result.data.items;

                    //绑定业务审批与流程关联表
                    workFlow_TableNameService.getAllWorkFlowTableNameListAsync().then(function (result) {
                        vm.workFlowTableNameList = result.data.items;

                        //绑定数据
                        workFlow_ProcessService.getWorkFlow_ProcessForEditAsync({
                            id: workFlow_ProcessId
                        }).then(function (result) {
                            vm.workFlow_Process = result.data.workFlow_Process;
                        });
                    });
                });

            }
            //执行初始化方法
            init();
        }
    ]);
})();